﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_DAL;
using Zor_Modes;
using Zor_Tools;

namespace Zor_Bll
{
    /// <summary>
    /// 街道管理
    /// create by liuyunfei at 2017/03/24
    /// </summary>

    public class Zor_Street_Bll<T> where T : class
    {
        /// <summary>
        /// 获取街道列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>

        public static List<T> GetPageList(dynamic model, int index, out int TotalCount, string where)
        {

            var DtID = RequestSession.GetSessionUser().DT_Id;  //获取当前登录的部门ID

            var sqlSurch = string.Empty;
            if (model.Bd_Name != null)
            {
                sqlSurch += " Bd_Name like '%" + model.Bd_Name + "%' and ";
            }

            if (model.Bd_Aname != null)
            {
                sqlSurch += " Bd_Aname like '%" + model.Bd_Aname + "%' and ";
            }
            if (model.Bd_IDNumber != null)
            {
                sqlSurch += " Bd_IDNumber like '%" + model.Bd_IDNumber + "%' and ";
            }
            if (model.Bd_Telephone != null)
            {
                sqlSurch += " Bd_Telephone like '%" + model.Bd_Telephone + "%' and ";
            }
            if (model.Bd_Sex != 0)
            {
                sqlSurch += " Bd_Sex = " + model.Bd_Sex + " and ";
            }
            sqlSurch += " Bd_Flage = 1 and Dt_Id = "+DtID+"";

            return PagerHelp<T>.GetPagerList(index, "V_Zor_Building", "Bd_CreateDate desc ", out TotalCount, sqlSurch);
        }

        /// <summary>
        /// 街道管理-修改
        /// </summary>
        /// <param name="building">街道对象</param>
        /// <returns>应答</returns>
        public static BaseAnswer UpdateBuilding(Zor_Building building)
        {
            BaseAnswer bar = Zor_Street_DAL<T>.UpdateBuilding(building);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "修改成功！" : "修改失败,请检查街道名称是否重复！";
            return bar;
        }

        /// <summary>
        /// 街道管理-新增
        /// </summary>
        /// <param name="building">街道对象</param>
        /// <param name="flage">标识</param>
        /// <returns>执行结果</returns>
        public static BaseAnswer InsertBuilding(Zor_Building building, int flage)
        {
            building.Bd_CreateDate = TimeHelper.ToNowTimeStamp();
            building.User_Id = RequestSession.GetSessionUser().User_Id;
            building.Bd_Flage = flage;
            BaseAnswer bar = Zor_Street_DAL<T>.InsertBuilding(building);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "增加成功！" : "新增失败，请检查街道名称是否重复！";
            return bar;
        }

        /// <summary>
        /// 街道删除
        /// </summary>
        /// <param name="id">街道ID集合</param>
        /// <returns></returns>
        public static BaseAnswer DeleteBuilding(int[] id)
        {
            BaseAnswer bar = Zor_Street_DAL<T>.DeleteBuilding(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "删除成功！" : "删除失败，请检查该街道下是否有门牌！";
            return bar;
        }

        /// <summary>
        /// 获取所属部门名称
        /// </summary>
        /// <returns></returns>
        public static List<T> GetDtName()
        {
            return Zor_Street_DAL<T>.GetDtName();
        }

        /// <summary>
        /// 获取街道管理列表（不分页）
        /// create Light by 2017/04/06       
        /// </summary>
        /// <returns></returns>
        public static List<T> GetList(string where)
        {
            return Zor_Street_DAL<T>.SelectViewBuilding(where);
        }


        /// <summary>
        /// 获取街道管理列表（不分页）
        /// create Light by 2017/04/06       
        /// </summary>
        /// <returns></returns>
        public static List<T> GetStreetList(string where)
        {
            return Zor_Street_DAL<T>.SelectViewStreet(where);
        }


    }
}
